﻿@model Apps.Models.WMS.WMS_Sale_OrderModel
@using Apps.Web.Core;
@using Apps.Common;
@using Apps.Models.WMS;
@using Apps.Web;
@using Apps.Locale;
@using Apps.Models.Sys;
@{
    ViewBag.Title = "确认销售订单";
    Layout = "~/Views/Shared/_Index_LayoutEdit.cshtml";
    List<permModel> perm = null;
}
<script type="text/javascript">
    $(function ()
    {
        //加载到货单
        $("#btnLoadSaleOrder").click(function ()
        {
            var billNum = $("#SellBillNum").val();
            $("#List").datagrid("load", { type: "confirm", billNum: billNum });
        });

        $("#btnSave").click(function ()
        {
            if (!$("form").valid()) {
                $.messageBox5s('提示', $("#ErrMesList").html());
                return;
            }
            if ($("form").valid())
            {
                var $dg = $('#List');
                var rows = $dg.datagrid('getRows');  
                if (rows.length)
                {
                    $.ajax({
                        url: "@Url.Action("Confirm")",
                        type: "Post",
                        data: { sellBillNum: $("#SellBillNum").val() },
                        dataType: "json",
                        success: function (data)
                        {
                            if (data.type == 1)
                            {
                                window.parent.frameReturnByMes(data.message);
                                window.parent.frameReturnByReload(true);
                                window.parent.frameReturnByClose()
                            } else
                            {
                                window.parent.frameReturnByMes(data.message);
                                hideLoading();

                            }
                        }
                    })
                }
            }
        });
        $("#btnReturn").click(function () {
            window.parent.frameReturnByClose();
        });

        $(window).resize(function () {
            $('#List').datagrid('resize', {

            }).datagrid('resize', {
                width: SetGridWidthSub(30),
                height: SetGridHeightSub(50)
            });
        });

    });
    $(function ()
    {
        $('#List').datagrid({
            url: '@Url.Action("GetSaleOrderByBillNum")?type=confirm&billNum=""',
            width: SetGridWidthSub(10),
            methord: 'post',
            height: SetGridHeightSub(100),
            fitColumns: true,
            idField: 'Id',
            pageSize: 15,
            pageList: [15, 20, 30, 40, 50],
            pagination: true,
            striped: true, //奇偶行是否区分
            singleSelect: false,//单选模式
            selectOnCheck: false,
            checkOnSelect: false,
            remotesort: false,
            showFooter: true,
            columns: [[
                { field: 'Id', title: 'Id', width: 80, hidden: true },
                { field: 'SaleBillNum', title: '销售单号（业务）', width: 80, sortable: true },
                { field: 'SellBillNum', title: '销售单号（系统）', width: 80, sortable: true },
                { field: 'PlanDeliveryDate', title: '计划发货日期', width: 80, sortable: true },
                { field: 'CustomerShortName', title: '客户', width: 80, sortable: true },
                { field: 'PartCode', title: '物料编码', width: 80, sortable: true },
                { field: 'Qty', title: '数量', width: 80, sortable: true },
                { field: 'BoxQty', title: '箱数', width: 80, sortable: true },
                { field: 'InvCode', title: '库房', width: 80, sortable: true },
                //{ field: 'SubInvId', title: '子库存', width: 80,sortable:true },
                { field: 'Lot', title: '批次号', width: 80, sortable: true },
            ]]
        });
    })


    //关闭模式窗口
    function frameReturnByClose() {
        $("#modalwindow").window('close');
    }

    //ifram 返回
    function frameReturnByClose() {
        $("#modalwindow").window('close');
    }

    function frameReturnByMes(mes) {
        $.messageBox5s('提示', mes);
    }
</script>

<div id="modalwindow" class="easyui-window" style="width:800px; height:400px;" data-options="modal:true,closed:true,minimizable:false,shadow:false"></div>
<div class="mvctool bgb">
    @Html.ToolButton("btnSave", "fa fa-save", Resource.Confirm, ref perm, "Save", true)
    @Html.ToolButton("btnReturn", "fa fa-reply", Resource.Reply, false)
</div>
@using (Html.BeginForm())
{
    <div id="ErrMesList">
        <div id="ErrMesListContent">
            @Html.ValidationSummary(false)
        </div>
    </div>
    @*@Html.HiddenFor(model => model.Id)*@
    <input id="inserted" type="hidden" name="inserted" value="" />
    <table class="formtable">
        <tbody>
            <tr>
                <th>
                    @Html.LabelFor(model => model.SellBillNum)：
                </th>
                <td>
                    <input id="SellBillNum" name="Supplier" type="text" style="width: 200px; display: inline;">
                    <a class="fa fa-plus-square color-gray fa-lg" id="selExc" href="javascript:showSelSaleOrderBillNum()"></a>
                    <script type="text/javascript">
                        function showSelSaleOrderBillNum()
                        {
                            $("#modalwindow").html("<iframe width='100%' height='100%' scrolling='no' frameborder='0'' src='/WMS/SaleOrder/SaleOrderLookUp?type=confirm'></iframe>");
                            $("#modalwindow").window({ title: '选择投料单', width: 720, height: 488, iconCls: 'fa fa-plus' }).window('open');
                        }

                        function SetSelResult(result, resultName)
                        {
                            $("#SellBillNum").val(resultName);
                        }

                    </script>
                    @Html.ToolButton("btnLoadSaleOrder", "fa fa-reply", Resource.Load, false)
                </td>
            </tr>

        </tbody>
    </table>
}
<table>
    <tr>
        <td colspan="7" style="padding:4px;">
            <table id="List"></table>
        </td>
    </tr>

</table>
